package com.sanyang.lawyer.controller.finance;

import com.sanyang.lawyer.ResultApi.ResponseResult;
import com.sanyang.lawyer.utils.FastDFSutils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: lawyer
 * @description: 财务文件上传
 * @author: lql
 * @create: 2019-11-08 11:34
 **/
@RestController
public class Financefast {

    @Autowired
    private FastDFSutils fastDFSutils;


    //文件上传测试
    @RequestMapping(value = "/upload/wenjian", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseResult uploadfile(MultipartRequest request){
        //将响应对象装换为文件对象
        HttpServletRequest request1 = (HttpServletRequest)request;
        //获取数据从request1 中获取
        String username = request1.getParameter("username");
        System.out.println(username);
        //文件对象
        MultipartFile file = request.getFile("file");
        //返回的是文件路径
        String filepath = null;
        try {
            filepath = fastDFSutils.uploadfile(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseResult.success(filepath);
    }
}
